package com.atguigu.pamentdemo.controller;

import com.atguigu.pamentdemo.entity.OrderInfo;
import com.atguigu.pamentdemo.enums.OrderStatus;
import com.atguigu.pamentdemo.service.impl.OrderInfoServiceImpl;
import com.atguigu.pamentdemo.service.orderInfoService;
import com.atguigu.pamentdemo.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "商品订单管理")
@CrossOrigin
@RestController
@RequestMapping("/api/order-info")
public class OrderInfoController {

    @Resource
    private orderInfoService orderInfoService;

    @ApiOperation("订单列表")
    @GetMapping("/list")
    public R list(){
      List<OrderInfo> list =  orderInfoService.listOrderByCreateTimeDesc();
      return R.ok().data("list",list);
    }

    /**
     * 查询本地订单状态
     */
    @ApiOperation("查询本地订单状态")
    @GetMapping("/query-order-status/{orderNo}")
    public R queryOrderStatus(@PathVariable String orderNo){
        String orderStatus = orderInfoService.getOrderStatus(orderNo);
        if (OrderStatus.SUCCESS.getType().equals(orderStatus)){
            return R.ok();
        }
        return R.ok().setCode(101).setMessage("支付中...");
    }
}
